<template>
	<view class="rectification-remind">
		<titleName :name="name" :backShow="true"></titleName>
		<view class="search-enterprise-wrap" v-if="showEnterprise">
			<view class="bgc">
				<view class="ipt-wrap">
					<input @confirm="getEnterpriseList" type="text" v-model="customername" placeholder="搜索公司名称"
						placeholder-class="ph-color" />
					<image @click="getEnterpriseList" :src="resourceUrl+'search-icon.png'" mode=""></image>
				</view>
				<view class="uni-list">
					<checkbox-group @change="checkboxChange">
						<label class="uni-list-cell uni-list-cell-pd" v-for="item in enterpriseList" :key="item.value">
							<view>
								<checkbox style="transform:scale(0.8)" :value="item.value" :checked="item.checked" />
							</view>
							<view>{{item.name}}</view>
						</label>
					</checkbox-group>
				</view>
				<view class="btn-wrap">
					<button class="save" @click="saveEnterprise">确认</button>
				</view>
			</view>

			<image class="err-btn" @click="showEnterprise=false" :src="resourceUrl+'black-err.png'" mode=""></image>

		</view>
		<view class="content-wrap">
			<view class="question">
				<view class="name">
					<text></text>公司名称
				</view>
				<button class="btn" @click="showEnterprise=true">
					选择
				</button>
			</view>
			<view class="ipt-wrap  enterprise">
				<textarea class="iptenter" v-model="selEnterprise" placeholder="请选择公司名称" disabled maxlength="-1"
					placeholder-class="areaipt-class"></textarea>
			</view>
			<view class="question">
				<view class="name">
					<text></text>整改内容
				</view>
			</view>
			<view class="ipt-wrap">
				<textarea v-model="params.content" placeholder="请输入文字内容" maxlength="-1"
					placeholder-class="ipt-class"></textarea>
			</view>
			<!-- <view class="phone-wrap">
				<view class="name"> <text>*</text> 联系电话</view>
				<view class="ipt">
					<image class="img" :src="resourceUrl+'mine-phone.png'" mode=""></image>
					<input type="text" v-model="params.mobile" placeholder="手机号码" placeholder-class="ipt-phone" />
				</view>
			</view> -->

			<view class="question">
				<view class="name">
					<text></text>整改期限
				</view>
				<view class="">
					<uni-datetime-picker @change="updateDate" type="daterange" v-model="single" />
				</view>
			</view>
			<view class="upload-phone">
				<view class="name">图片</view>
				<view style="display: flex;flex-wrap: wrap;">
					<view class="upload" @click="checkImage" style="margin-right: 20rpx;">
						<image :src="resourceUrl+'mine-upload-icon.png'" mode="">
						</image>
						<text>（选择照片）</text>
					</view>
					<view :class="['for-image',index==2?'sb':'']" v-for="(item,index) in images" :key="index">
						<image :src="item" mode="">
						</image>
						<view class="dele" @click="deleImage(index)">✕</view>
					</view>
				</view>
			</view>
			<view class="btn-wrap">
				<button @click="submit">发布</button>
			</view>
		</view>
	</view>
</template>

<script setup>
	import titleName from '../../components/titleName.vue'
	import http from '../../request/index'
	import {
		onShow
	} from '@dcloudio/uni-app'
	import {
		resourceUrl
	} from '../../request/config'
	import uploadFile from '../../request/uploadFile.js'
	import {
		reactive,
		ref
	} from 'vue'
	let name = "整改期限提醒"
	let images = reactive([])
	let selValue = ref('')
	let recordSelVal = ref()
	let params = reactive({
		title: '整改期限提醒'
	})
	let showEnterprise = ref(false)
	let single = ref('')
	let selEnterprise = ref([])
	let enterpriseList = ref([])
	let customername = ref('')
	onShow(() => {
		getEnterpriseList()
	})
	let getEnterpriseList = () => {
		http({
			url: "/enterprise/datalist",
			data: {
				customername: customername.value
			}
		}).then((res) => {
			if (res.code == 0) {
				enterpriseList.value = res.data.list.map((item) => {
					return {
						name: item.customername,
						value: item.id,
						checked: false
					}
				})
			}
		})
	}
	let checkImage = () => {
		uni.chooseImage({
			sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
			count: 10,
			success: function(res) {
				let tempFilePaths = res.tempFilePaths
				console.log(tempFilePaths, 'tempFilePaths');
				for (var i = 0; i < tempFilePaths.length; i++) {
					uploadFile({
						filePath: tempFilePaths[i]
					}).then((res) => {

						if (res.code == 0) {
							images.push(res.data.url)

							// enterpriseMsg.authbook = res.data.url
						}

					})
				}
			}
		});

	}
	let save = () => {}
	let updateDate = (e) => {
		if (e.legnth == 0) {
			params.monitorstarttime = ''
			params.monitorendtime = ''
			return
		}
		params.monitorstarttime = e[0]
		params.monitorendtime = e[1]

	}
	let deleImage = (index) => {

		images.splice(index, 1)

	}
	let saveEnterprise = () => {
		let selVal = recordSelVal.value
		
		params.groupid = selVal.join(',')

		selEnterprise.value.length = 0
		for (let i = 0; i < enterpriseList.value.length; i++) {
			if (selVal.includes(String(enterpriseList.value[i].value))) {
				enterpriseList.value[i].checked = true
				selEnterprise.value.push(enterpriseList.value[i].name)
			} else {

				enterpriseList.value[i].checked = false
			}
		}

		showEnterprise.value = false

	}
	let checkboxChange = (e) => {
		console.log(e,'ee');
		recordSelVal.value = e.detail.value;


	}
	let submit = () => {

		if (!params.groupid) {
			uni.showToast({
				title: '请选择企业',
				icon: "none"
			})
			return
		}
		if (!params.monitorendtime) {
			uni.showToast({
				title: '请选择整改期限',
				icon: "none"
			})
			return
		}
		if (!params.content) {
			uni.showToast({
				title: '请输入整改内容',
				icon: "none"
			})
			return
		}
		http({
			url: '/greenAdmReformTip/addOrUpdate',
			data: {
				...params,
				attachmenturl: images.join(','),

			},

		}).then((res) => {
			if (res.code == 0) {
				uni.showToast({
					title: '提交成功',
					icon: 'none'
				})

				for (let key in params) {
					if(key=='title')continue
					params[key] = ''
				}
				
				single.value = ''
				images.length = 0
				selEnterprise.value.length = 0

			}

		})
	}
</script>

<style lang="scss" scoped>
	:deep(.uni-date-editor) {
		width: 515rpx;
		height: 79rpx;
		background: #FAFAFA;
		border-radius: 14rpx;

	}

	checkbox {
		border-radius: 7rpx;
	}

	:deep(.uni-list) {
		height: 650upx;
		overflow: scroll;
		padding: 40upx 0 0upx 30upx;
	}

	:deep(.uni-list-cell:first-child) {

		margin-top: 0upx !important;
	}

	:deep(.uni-list-cell) {

		font-family: Source Han Sans CN;
		font-weight: 400;
		font-size: 28rpx;
		color: #333333;

	}

	:deep(.uni-list-cell) {
		display: flex;
		align-items: center;
		margin-top: 40upx;
	}

	:deep(.checkbox) {}

	:deep(.areaipt-class) {
		

		
		padding-top: 100upx;
		font-weight: 400;
		font-size: 31rpx;
		color: #BFBEBE;
	}

	:deep(.ipt-class) {

		font-weight: 400;
		font-size: 31rpx;
		color: #BFBEBE;


	}

	:deep(.ipt-phone) {

		font-weight: 500;
		font-size: 31rpx;
		color: #BFBEBE;

	}

	.rectification-remind {
		width: 100vw;
		height: 100vh;
		// padding-top: 160rpx;
		padding-bottom: 50rpx;

		.search-enterprise-wrap {
			position: fixed;
			background-color: rgba(0, 0, 0, .7, );
			left: 0;
			top: 0;
			width: 100vw;
			height: 100vh;
			z-index: 10;

			padding: 135upx 30upx 135upx 30upx;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;

			.bgc {
				width: 100%;
				height: 942rpx;
				background: #FFFFFF;
				border-radius: 21rpx;
				padding: 30upx 0upx 40upx 0upx;

				.btn-wrap {
					margin-top: 72upx;
					padding: 0 50upx;

					.save {
						width: 100%;
						height: 88rpx;
						background: #0874FA;
						border-radius: 44rpx;
						text-align: center;


						font-family: Source Han Sans CN;
						font-weight: 500;
						font-size: 31rpx;
						color: #FFFFFF;
						line-height: 88rpx;
					}
				}


				.ipt-wrap {
					width: 640upx;
					display: flex;
					align-items: center;
					margin: 0 auto;
					height: 73rpx;
					background: #FFFFFF;
					border-radius: 14rpx;
					border: 1px solid #0874FA;
					padding-right: 34upx;
					padding-left: 30upx;

					input {
						flex: 1;
						padding-right: 50upx;
					}

					image {
						width: 35upx;
						height: 35upx;
					}
				}
			}

			.err-btn {
				width: 57upx;
				height: 57upx;
				margin-top: 54upx;
			}
		}

		.content-wrap {
			height: calc(100vh - 160upx);
			overflow: scroll;
			padding-bottom: 100upx;

			.question {
				margin-top: 40rpx;
				padding-left: 31rpx;
				margin-bottom: 32rpx;
				font-weight: 400;
				font-size: 33rpx;
				padding-right: 40upx;
				color: #000;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.name {
					text {
						color: #F82A24;
					}
				}

				.btn {
					width: 144rpx;
					height: 62rpx;
					background: #0874FA;
					border-radius: 14rpx;

					font-family: Source Han Sans CN;
					font-weight: 400;
					font-size: 35rpx;
					color: #FFFFFF;
					line-height: 62rpx;
					text-align: center;
				}



			}

			.btn-wrap {
				padding: 0 39rpx;
				margin-top: 104rpx;

				button {
					width: 100%;
					height: 88rpx;
					background: #0874FA;
					border-radius: 44rpx;

					font-weight: 400;
					font-size: 34rpx;
					color: #FFFFFF;
					line-height: 88upx;

				}
			}

			.upload-phone {
				margin-top: 40rpx;
				padding-left: 45rpx;


				.name {

					font-weight: 500;
					font-size: 33rpx;
					color: #000000;
					margin-bottom: 30rpx;

				}

				.for-image {
					margin-right: 20rpx;
					margin-top: 20rpx;
					position: relative;

					image {
						border-radius: 10upx;
						width: 150rpx;
						height: 150rpx;
					}
				}

				.dele {
					position: absolute;

					width: 30rpx;
					height: 30rpx;
					background: #989A9E;
					position: absolute;
					border-radius: 50%;
					right: -15rpx;
					top: -15rpx;
					color: #FFFFFF;
					display: flex;
					font-size: 17rpx;
					align-items: center;
					justify-content: center;
				}



				.for-image:nth-of-type(1),
				.for-image:nth-of-type(2),
				.for-image:nth-of-type(3) {
					margin-top: 0rpx !important;
				}

				.sb {
					margin-top: 0rpx;
				}

				.upload {
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: center;
					width: 149rpx;
					height: 149rpx;
					background: #FFFFFF;
					border-radius: 7rpx;
					border: 2px dashed #BFBFBF;

					image {
						width: 40rpx;
						height: 35rpx;
					}

					text {
						margin-top: 11rpx;
						font-weight: 400;
						font-size: 15rpx;
						color: #999999;

					}
				}
			}

			.phone-wrap {
				padding-left: 48rpx;
				padding-right: 48rpx;
				margin-top: 30rpx;

				.name {
					width: 100%;

					font-weight: 400;
					font-size: 33rpx;
					color: #000;

					text {
						color: #F82A24;
					}
				}

				.ipt {
					margin-top: 20rpx;
					display: flex;
					align-items: center;
					border-bottom: 2rpx solid #AAAAAA;
					height: 89rpx;
					width: 100%;

					.img {
						width: 35rpx;
						height: 35rpx;
						margin-right: 33rpx;
					}

					input {
						flex: 1;
					}
				}


			}

			.ipt-wrap.enterprise {

				height: 100rpx;
				padding-top: 0;
				line-height: 100rpx;
				padding-bottom: 0;
				display: flex;
				align-items: center;

				.iptenter {
					width: 100%;
					height: 50rpx;

					line-height: 50rpx;

				}
			}

			.ipt-wrap {

				width: 693rpx;
				max-height: 376rpx;
				margin: 0 auto;

				padding-left: 24rpx;
				padding-top: 30rpx;
				background: #FAFAFA;
				border-radius: 14rpx;
				border: 1px solid #BFBFBF;
				padding-bottom: 20upx;

				textarea {
					width: 100%;


				}
			}
		}





	}
</style>